package com.riddle.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import com.riddle.model.Menu;
import com.riddle.model.Permission;
import com.riddle.util.StringUtil;

@Repository
@Scope("prototype")  
public class PermissionDao extends BaseDao<Permission> {
	
	public List<Permission> queryParent(){
		return super.query("selectParentPermission");
	}
	
	public Permission query(Long id){
		return super.query(id, "selectPermissionById");
	}
	
	public List<Permission> queryModelByPage(Integer page, Integer rows, String query){
		String statement = null;
		if(StringUtil.isNullOrEmpty(query)) {
			statement = "selectPermissionTree";
		} else {
			statement = "selectPermissionForQuery";
		}
		return super.queryModelByPage(page, rows, query, statement);
	}
	
	public void insert(Permission model) {
		super.insert(model, "insertPermission");
	}
	
	public void update(Permission model) {
		super.update(model, "updatePermission");
	}
	
	public void delete(Long id) {
		super.delete(id, "deletePermission");
	}
	
	public List<Permission> getPermissionTree(){
		return super.query("selectPermissionTree");
	}
}
